Imports CupsApp.Service
Imports CupsApp.Data
Imports System.Web.DomainServices


Public Class ClientController
    Inherits System.Web.Mvc.Controller

    '
    ' GET: /Client/

    Function Index() As ActionResult
        Return View()
    End Function

    '
    ' GET: /Client/Details/5

    Function Details(ByVal id As Integer) As ActionResult
        Return View()
    End Function

    '
    ' GET: /Client/Create

    Function Create() As ActionResult
        Return View()
    End Function

    '
    ' POST: /Client/Create

    <AcceptVerbs(HttpVerbs.Post)> _
    Function Create(ByVal collection As FormCollection) As ActionResult
        Try
            ' TODO: Add insert logic here
            Return RedirectToAction("Index")
        Catch
            Return View()
        End Try
    End Function

    '
    ' GET: /Client/Edit/5

    Function Edit(ByVal id As Integer) As ActionResult
        Return View()
    End Function

    '
    ' POST: /Client/Edit/5

    <AcceptVerbs(HttpVerbs.Post)> _
    Function Edit(ByVal id As Integer, ByVal collection As FormCollection) As ActionResult
        Try
            ' TODO: Add update logic here

            Return RedirectToAction("Index")
        Catch
            Return View()
        End Try
    End Function

    Function ShowClients() As ActionResult

        Dim domainService As IClientDomainService = DomainServiceProxy.Create(Of CupsDomainService)()

        Dim clients = From c In domainService.GetClients() _
                      Select New With {c.ID, c.LastName, c.FirstName, c.cups_CurrentClientStatus.cups_StatusUpdateType.Name, c.DateStarted, c.cups_CurrentClientStatus.UpdatedOn}


        Dim cSummaries As New List(Of ClientSummary)
        Dim cSummary As ClientSummary

        For Each c In clients
            cSummary = New ClientSummary()
            cSummary.ID = c.ID
            cSummary.FirstName = c.FirstName
            cSummary.LastName = c.LastName
            cSummary.CurrentStatus = c.Name
            cSummary.DateStarted = c.DateStarted
            If (IsNothing(c.UpdatedOn)) Then
                cSummary.LastUpdateDays = 0
            Else
                cSummary.LastUpdateDays = DateTime.Now.Subtract(c.UpdatedOn).Days
            End If
            cSummaries.Add(cSummary)
        Next


        Return View(cSummaries)

    End Function
    Function NewClient() As ActionResult
        Return View()
    End Function
    Function ShowBackgroundInterview() As ActionResult
        Return View()
    End Function

    Function ShowHealthInterview() As ActionResult
        Return View()
    End Function

    Function HousingInterview() As ActionResult
        Return View()
    End Function
    Function ShowStatus() As ActionResult
        Return View()
    End Function

    Function ShowExitInterview(ByVal clientID As Integer) As ActionResult
        Dim domainService As IInterviewDomainService = DomainServiceProxy.Create(Of CupsDomainService)()

      
        Return View(New cups_Interview())
    End Function

    Function ShowHousingInterview() As ActionResult
        Return View()
    End Function



End Class
